package com.cactus.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cactus.entity.Goods;
import com.cactus.entity.GoodsOrder;
import com.cactus.mapper.GoodsMapper;
import com.cactus.service.GoodsOrderService;
import com.cactus.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class GoodsServiceImpl
        extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Autowired
    private GoodsOrderService goodsOrderService;

    @Override
    public String selectMaxCourierNumber() {
        return goodsMapper.selectMaxCourierNumber();
    }


    /**
     * 接单
     *
     * @param goodsOrder
     */
    @Override
    public void takeOrders(GoodsOrder goodsOrder) {
        goodsOrderService.save(goodsOrder);
        Goods goods = new Goods();
        goods.setId(goodsOrder.getGoodsId());
        goods.setStatus("1");
        updateById(goods);
    }

    @Override
    public void signed(GoodsOrder goodsOrder) {
        goodsOrder.setSignedTime(new Date());
        goodsOrderService.updateById(goodsOrder);
        Goods goods = new Goods();
        goods.setId(goodsOrder.getGoodsId());
        goods.setStatus("2");
        updateById(goods);
    }
}
